{extend name="base"/}
{block name="resources"}
{/block}
{block name="main"}
<!-- 搜索框 -->
<div class="ns-screen layui-collapse" lay-filter="selection_panel">
	<div class="layui-colla-item">
		<h2 class="layui-colla-title">筛选</h2>
		<form class="layui-colla-content layui-form layui-show">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">开始-结束时间：</label>
					<div class="layui-input-inline">
						<div class="layui-input-inline">
							<input type="text" class="layui-input ns-len-short" placeholder="开始时间" name="start_date" id="start_time" readonly>
						</div>
						<div class="layui-input-inline end-time">
							<input type="text" class="layui-input ns-len-short" placeholder="结束时间" name="end_date" id="end_time" readonly>
						</div>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">周期类型：</label>
					<div class="layui-input-inline">
						<select name="status" lay-filter="period_type">
							<option value="">全部</option>
							<option value="1">按天</option>
							<option value="2">按周</option>
							<option value="3">按月</option>
						</select>
					</div>
				</div>
			</div>
			<div class="ns-form-row">
				<button class="layui-btn ns-bg-color" lay-submit lay-filter="search">筛选</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</form>
	</div>
</div>

<table id="period_account_list" lay-filter="period_account_list"></table>

<!--时间-->
<script type="text/html" id="times">
	<div class="layui-elip">{{ns.time_to_date(d.end_time)}}</div>
</script>

<!--状态-->
<script type="text/html" id="period_type">
	{{# if(d.period_type == 1){ }}
    <div class="layui-elip">按天</div>
    {{# }else if(d.period_type == 2){ }}
    <div class="layui-elip">按周</div>
    {{# }else if(d.period_type == 3){ }}
    <div class="layui-elip">按月</div>
    {{# } }}
</script>

<!--操作-->
<script type="text/html" id="action">
	<div class="ns-table-btn">
		<a class="layui-btn" lay-event="basic">查看</a>
	</div>
</script>
{/block}

{block name="script"}
<script>
	layui.use(['form', 'laydate'], function() {
		var table,
			form = layui.form,
			laydate = layui.laydate,
			currentDate = new Date(),
			minDate = "";
			
		currentDate.setDate(currentDate.getDate() - 7);
		form.render();

		//开始时间
		laydate.render({
			elem: '#start_time',
			type: 'datetime'
		});

		//结束时间
		laydate.render({
			elem: '#end_time',
			type: 'datetime'
		});

		/**
		 * 重新渲染结束时间
		 */
		function reRender(){
		    $("#end_time").remove();
		    $(".end-time").html('<input type="text" class="layui-input" placeholder="申请结束时间" name="end_date" id="end_time" >');
		    laydate.render({
		        elem: '#end_time',
		        type: 'datetime',
		        min: minDate
		    });
		}

		/**
		 * 表格加载
		 */
		table = new Table({
			elem: '#period_account_list',
			url: ns.url("admin/shopaccount/period"),
			cols: [
				[{
					field: 'money',
					title: '结算金额',
					width: '10%',
					unresize: 'false'
				}, {
					field: 'shop_num',
					title: '结算店铺数量',
					width: '15%',
					unresize: 'false'
				},{
					field: 'period_type',
					title: '周期类型',
					width: '10%',
					unresize: 'false',
					templet: '#period_type'
				},{
					title: '账期截止时间',
					width: '14%',
					unresize: 'false',
					templet: '#times'
				}, {
                    field: 'remark',
                    title: '备注',
                    width: '15%',
                    unresize: 'false'
                }, {
					title: '操作',
					width: '8%',
					toolbar: '#action',
					unresize: 'false'
				}]
			]
		});
		
		/**
		 * 搜索功能
		 */
		form.on('submit(search)', function(data) {
			table.reload({
				page: {
					curr: 1
				},
				where: data.field
			});
			return false;
		});

		/**
		 * 监听工具栏操作
		 */
		table.tool(function(obj) {
			var data = obj.data,
				event = obj.event;
            switch (obj.event) {
                case 'basic': //查看
                    location.href = ns.url("admin/shopaccount/periodWithdrawList?period_id=" + data.period_id);
                    break;
            }
		})
	});
</script>
{/block}